package com.miracle.main.module.mvp.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.miracle.basemvp.base.state.StateController;
import com.miracle.basemvp.di.component.AppComponent;
import com.miracle.common.base.BaseListFragment;
import com.miracle.common.view.RefreshView;
import com.miracle.main.R;
import com.miracle.main.R2;
import com.miracle.main.adapter.GlideImageLoader;
import com.miracle.main.adapter.SecreteAdapter;
import com.miracle.main.module.di.component.DaggerSecretComponent;
import com.miracle.main.module.di.module.SecretModule;
import com.miracle.main.module.mvp.contract.SecretContract;
import com.miracle.main.module.mvp.entity.bean.SecretBean;
import com.miracle.main.module.mvp.entity.request.SecretListRequest;
import com.miracle.main.module.mvp.presenter.SecretPresenter;
import com.miracle.main.module.mvp.ui.activity.AddSecretActivity;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.youth.banner.Banner;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * com.miracle.main.module.mvp.ui.fragment
 * (c)2018 AIR Times Inc. All rights reserved.
 *
 *
 * @author WangJQ
 * @version 1.0
 * @date 2018/7/2 18:04
 * @see com.miracle.main.module.mvp.ui.fragment
 */
public class SecretFragment extends BaseListFragment<SecretPresenter, SecretBean> implements
        SecretContract.View {

    @BindView(R2.id.btn)
    FloatingActionButton mBtn;
    @BindView(R2.id.banner)
    Banner mBanner;
    @BindView(R2.id.rv_file_list)
    RecyclerView mRecyclerView;
    @BindView(R2.id.srl_file_list)
    SmartRefreshLayout mSmartRefreshLayout;

    @Inject
    SecreteAdapter mAdapter;
    @Inject
    ArrayList<SecretBean> mList;

    @Override
    public int setLayoutId(@Nullable Bundle bundle) {
        return R.layout.cloud_fragment_secret;
    }

    @Override
    public void setDaggerComponent(AppComponent appComponent) {
        DaggerSecretComponent
                .builder()
                .appComponent(appComponent)
                .secretModule(new SecretModule(this))
                .build()
                .inject(this);
    }

    @Override
    protected void initStateController() {
        super.initStateController();
        mStateController = new StateController.Builder()
                .initBuilder(this)
                .setLayoutState(R.id.ll_no_data_file_list)
                .setSmartRefreshLayout(R.id.srl_file_list)
                .setLoadingLayout(R.id.frame_progress)
                .build();
    }

    @Override
    public void init(@Nullable Bundle bundle) {
        initAdapter();
    }

    @Override
    public void initView() {
        ArrayList<String> images = new ArrayList<>();
        images.add("http://111.231.226.202/300320180713103643/resources/20180622230020_qbfye.jpg");
        images.add("http://111.231.226.202/300320180713103643/resources/20160422231508_utXdK.jpeg");
        images.add("http://111.231.226.202/300320180713103643/resources/201822144145_cYwNv.jpeg");
        mBanner.setImageLoader(new GlideImageLoader());
        //设置图片集合
        mBanner.setImages(images);
        //banner设置方法全部调用完毕时最后调用
        mBanner.start();
    }

    @Override
    public void initData() {
        mSmartRefreshLayout.setOnRefreshListener(this);
        mSmartRefreshLayout.setOnLoadmoreListener(this);
    }

    private void initAdapter() {
        mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        mRecyclerView.setAdapter(mAdapter);
    }

    @Override
    public List<SecretBean> setList() {
        return mList;
    }

    @Override
    public RecyclerView.Adapter setAdapter() {
        return mAdapter;
    }

    @Override
    public void requestData() {
        mPresenter.getList(providerEvent(), new SecretListRequest(), mStateController);
    }

    @OnClick(R2.id.btn)
    public void onViewClicked(View view) {
        int id = view.getId();
        if (id == R.id.btn) {
            startActivity(new Intent(mContext, AddSecretActivity.class));
        }
    }

}
